#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 114;
const int NM = 3e3 + 114;
const int M = 1e6 + 114;
const int nm = NM * NM * 4;
int t;
int d[N], v[N], a[N], p[N], st[N], ed[N], sum[M], lft[N], rgt[N], Sum[NM][NM];
map<int, bool> mp;
int tree[nm], tag[nm];
bool vis[N];
int ans = 0;
inline void dfs(int x, int m, int t){
    if(x > m){
        for(int i = 1;i <= t; i++){
            for(int j = 1;j <= m; j++){
                if(vis[j]){
                    continue;
                }
                if(lft[i] <= j && j <= rgt[i]){
                    if(Sum[lft[i]][rgt[i]] > 1){
                        Sum[lft[i]][rgt[i]] --;
                    }
                    else{
                        return ;
                    }
                }
            }
        }
        ans ++;
    }
    vis[x] = true;
    dfs(x + 1, m, t);
    vis[x] = false;
    dfs(x + 1, m, t);
}
signed main(){
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    for(int i = 1;i <= t; i++){
        int n, m;
        int L, V;
        cin >> n >> m >> L >> V;
        for(int j = 1;j <= n; j++){
            cin >> d[j] >> v[j] >> a[j];
        }
        for(int j = 1;j <= m; j++){
            cin >> p[j];
            mp[p[j]] = true;
        }
        int T;
        T = 0;
        for(int j = 1;j <= L; j++){
            sum[j] = sum[j - 1] + mp[j];
        }
        for(int j = 1;j <= n; j++){
            if(v[j] > V && a[j] >= 0){
                st[++T] = d[j];
                ed[T] = L;
                continue;
            }
            if(v[j] == V && a[j] == 0){
                continue;
            }
            if(v[j] < V && a[j] <= 0){
                continue;
            }
            double L1 = L, V1 = V;
            double t = (V1 - v[j]) / a[j];
            double End = d[j] * t + 0.5 * a[j] * t * t + 0.0001;
            int Endr = ceil(End);
            int Endr2 = int(End - 0.5);
            Endr += d[j];
            Endr2 += d[j];
            if(a[j] >= 0){
                st[++ T] = Endr;
                ed[T] = L;
            }
            else{
                st[++ T] = d[j];
                ed[T] = Endr2;
            }
        }
        for(int j = 1;j <= T; j++){
            lft[j] = sum[st[j] - 1] + 1;
            rgt[j] = sum[ed[j]];
            Sum[lft[j]][rgt[j]] ++;
        }
        dfs(1, m, T);
        cout << ans << endl;
    }
    return 0;
}